package api

import (
	"beesoft.ink/application/garage/app/helper"
	"beesoft.ink/application/garage/app/model"
	"beesoft.ink/application/garage/app/service"
	"fmt"
	"github.com/labstack/echo/v4"
)

var Area area

type area struct{}

func (r area) List(ctx echo.Context) error {
	var req model.AreaListReq
	err := ctx.Bind(&req)
	if err != nil {
		panic(err)
	}
	helper.SetDefaults(&req)

	res := service.Area.List(ctx, &req)
	return helper.NewResponse(ctx).ResponseOk(res)
}
func (r area) Show(ctx echo.Context) error {
	item, err := service.Area.Show(ctx)
	if err != nil {
		fmt.Println(err)
		//panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk(item)
}
func (r area) Store(ctx echo.Context) error {
	//var req *model.AreaStoreReq

	err := service.Area.Store(ctx)
	if err != nil {
		panic(err)
	}
	return helper.NewResponse(ctx).ResponseCreated()
}
func (r area) Update(ctx echo.Context) error {
	//var req *model.AreaUpdateReq
	// id := c.Param("id")
	err := service.Area.Update(ctx)
	if err != nil {
		panic(err)
	}

	return helper.NewResponse(ctx).ResponseOk()
}
func (r area) Destroy(ctx echo.Context) error {
	id, err := helper.ParseUintParam(ctx, "id")
	if err != nil {
		panic(err)
	}

	err = service.Area.Destroy(ctx, id)
	if err != nil {
		ctx.Logger().Info("Area Destroy error: %+v", err)
	}

	return helper.NewResponse(ctx).ResponseOk()
}
